<template>
  <div>
    <h1>分类添加</h1><hr>
    <el-table
        :data="tableData"
        style="width: 100%;margin-bottom: 20px;"
        row-key="id"
        border
        default-expand-all:false
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <el-table-column
          prop="id"
          label="ID"
          sortable
          width="180">
      </el-table-column>
      <el-table-column
          prop="name"
          label="分类"
          sortable
          width="180">
      </el-table-column>
      <el-table-column
          prop="orders"
          label="排序"
          width="180">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
              size="mini"
              @click="handleadd(scope.row.id)">添加</el-button>
          <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
<!--  添加分类  -->
    <el-dialog title="添加分类" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="分类名称" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="排序" :label-width="formLabelWidth">
          <el-input v-model="form.orders" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addType">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "TypeView",
  data(){
    return{
      tableData:[],
      dialogFormVisible:false,
      formLabelWidth:'120px',
      form:{}
    }
  },methods:{
    list(){
      this.axios.post("http://localhost:8003/api/tb-goods/typeList").then(res=>{
        this.tableData=res.data
      })
    },handleadd(id){
      //alert(id)
      this.dialogFormVisible=true
      this.form.parentId=id;
    },
    addType(){
      this.axios.post("http://localhost:8003/api/tb-goods/addType",this.form).then(res=>{
        if(res.data=='success'){
          console.log(res.data);
          this.dialogFormVisible=false;
          this.list();
        }
      })
    }
  },created() {
    this.list();
  }
}
</script>

<style scoped>

</style>